<!DOCTYPE html>
<html>
<head>
	<title>Axios的基本使用</title>
	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
	<button onclick="testAxios()">测试</button>
	<script type="text/javascript">
		function testAxios(){
			//使用axios发送get请求,then是返回数据的回调函数,value.data是返回值
			axios.get("http://localhost:8088/user/1")
				.then(function(value){
					console.log(value.data);
					alert(value.data.data.userName);
				});
			//使用axios实现post请求,post后面的参数｛｝是发给后台的数据
			axios.post("http://localhost:8088/user",{userId:0,userName:"测试1",userPassword:"123",userRealname:"测试1",userTel:"16994443333",userAddress:"不知道"})
				.then(function(value){
					console.log(value.data);
					if(value.data.msg=="success"){
						alert("添加成功");
					}
				});
			//put请求
			axios.put("http://localhost:8088/user",{userId:32,userName:"测试123",userPassword:"123",userRealname:"测试123",userTel:"16994443333",userAddress:"不知道123"})
				.then(function(value){
					console.log(value.data);
					if(value.data.msg=="success"){
						alert("更新成功");
					}
				});
			//delete请求
			axios.delete("http://localhost:8088/user/32")
				.then(function(value){
					console.log(value.data);
					if(value.data.msg=="success"){
						alert("删除成功");
					}
				});
		}
	</script>
</body>
</html>